<?php
namespace control;
// 发起审批
class initiateApprovalClass extends adIndexClass
{
    /**
     * 数据
     *
     * @return array
     */
    protected static function prepareData(): array
    {
        $data[L('person.table.ren_li_zi_yuan')] = [
            L('person.table.yrsq') => [
                'cla' =>'recruitment',
                'fun' =>'edit',
            ],
            L('person.table.zpjhsp') => [
                'cla' =>'recruitmentPlan',
                'fun' =>'edit',
            ],
            L('person.table.pxjhsp') => [
                'cla' =>'trainingPlan',
                'fun' =>'edit',
            ],
            L('person.table.ji_xiao_zi_ping') => [
                'cla' =>'performanceScore',
                'fun' =>'edit',
//                'para'=>['source'=>'initiate']//携带参数
            ],
            L('person.table.bu_ka_shen_qing') => [
                'cla' =>'workSignAdd',
                'fun' =>'edit',
            ],
            L('person.table.qjsq') => [
                'cla' =>'work',
                'fun' =>'edit',
            ],
            L('person.table.wcsq') => [
                'cla' =>'workOut',
                'fun' =>'edit',
            ],
            L('person.table.ccsq') => [
                'cla' =>'bussinessTrip',
                'fun' =>'edit',
            ],
            L('person.table.jbsq') => [
                'cla' =>'workAdd',
                'fun' =>'edit',
            ],
            L('person.table.zzsq') => [
                'cla' =>'staffFormal',
                'fun' =>'edit',
            ],
            L('person.table.dgsq') => [
                'cla' =>'jobApply',
                'fun' =>'edit',
            ],
            L('person.table.gssq') => [
                'cla' =>'staffInjury',
                'fun' =>'edit',
            ],
            L('person.table.lzsq') => [
                'cla' =>'staffQuitRecord',
                'fun' =>'edit',
            ],
        ];
        $data[L('person.table.xzgl')] = [
            L('person.table.bgyplysq') => [
                'cla' =>'materialOut',
                'fun' =>'edit',
            ],
            L('person.table.ycsq') => [
                'cla' =>'carRecord',
                'fun' =>'edit',
            ],
            L('person.table.hyssq') => [
                'cla' =>'meetingRecord',
                'fun' =>'room',
            ],
            L('person.table.yzsq') => [
                'cla' =>'sealRecord',
                'fun' =>'edit',
            ],
        ];

        $data[L('person.table.cai_wu_guan_li')] = [
            L('person.table.gdzclysq') => [
                'cla' =>'assetUse',
                'fun' =>'editPage',
            ],
            L('person.table.gdzchjsp') => [
                'cla' =>'assetCut',
                'fun' =>'editPage',
            ],
            L('person.table.fysq') => [
                'cla' =>'feeApply',
                'fun' =>'edit',
            ],
            L('person.table.fybxsq') => [
                'cla' =>'cost',
                'fun' =>'edit',
            ],
            L('person.table.fksq') => [
                'cla' =>'payment',
                'fun' =>'edit',
            ],
        ];
        return $data;
    }

    /**
     * 返回网页
     *
     * @return string
     */
    public function home()
    {
        $onion = [L('person.table.grzx'), L('person.table.wo_de_shen_pi'), L('person.table.fa_qi_shen_pi')];
        $data = self::prepareData();
        $html = '';
        $page = array_keys($this->controlPower);
        foreach ($data as $title => $array) {
            if(!empty($array) && $this->powerIn($array, $page)){
                $html .= '<h4 class="initiate-title">'.$title.'</h4>';
                $html .= '<ul class="initiate-ul">';
                foreach ($array as $name => $value) {
                    $para = '';//携带参数
                    if (!empty($value['para']) && is_array($value['para'])){
                        foreach ($value['para'] as $k=>$item){
                            $para.="&{$k}=".$item;
                        }
                    }
                    //有此页面权限才展示
                    if (in_array($value['cla'],$page)){
                        $url = $this->root.'control/adIndex.html?cla='.$value['cla'].'&fun='.$value['fun'].'&source=initiate'.$para;
                        $html .= '<li onclick="newIframe(\''.L('person.table.initiate').'-'.$name.'\', \''.$url.'\')">'.$name.'</li>';
                    }
                }
                $html .= "</ul>\n<hr class='space'>";
            }
        }
        $html = $html ?: '<span>'.L('person.table.no_audit').'</span>';
        $html =<<<EOT
        <div class="container">
            {$html}
        </div>

EOT;
        return head("ad").$this->adheader($onion).$html.warn().$this->adfooter();
    }

    /**
     * 判断权限
     * @param $power
     * @param $page
     * @return bool
     */
    public function powerIn($power,$page){
        $bool = false;
        foreach ($power as $value) {
            if (in_array($value['cla'], $page)){
                $bool = true;
                break;
            }
        }
        return $bool;
    }

}
